/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmConjunto.java
 *
 * Created on 04-dic-2014, 8:35:51
 */
package piii.presentacion;

import PIII.Negocio.Conjunto;
import PIII.Negocio.Entero;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author sistemas
 */
public class FrmConjunto extends javax.swing.JFrame {

    private void DimencionarVectorResultado(int NroColumnas){
        DefaultTableModel Modelo =new DefaultTableModel();
        this.jTable3.setModel(Modelo);
        for(int i=0;i<=NroColumnas-1;i++){
            Modelo.addColumn(Integer.toString(i));
        }
        Object[] fila=new Object[1];
        Modelo.addRow(fila);
    }
    private void dimensionar(int NroColumnas){
        DefaultTableModel Modelo =new DefaultTableModel();
        this.jTable1.setModel(Modelo);
        for(int i=0;i<=NroColumnas-1;i++){
            Modelo.addColumn(Integer.toString(i));
        }
        Object[] fila=new Object[1];
        Modelo.addRow(fila);
        
        DefaultTableModel Modelo2 =new DefaultTableModel();
        this.jTable2.setModel(Modelo2);
        for(int i=0;i<=NroColumnas-1;i++){
            Modelo2.addColumn(Integer.toString(i));
        }
        Object[] fila2=new Object[1];
        Modelo2.addRow(fila2);
        
    }
    /** Creates new form FrmConjunto */
    public FrmConjunto() {
        initComponents();
        this.dimensionar(4);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btnUnion = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("{A}=");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(jTable3);

        jLabel2.setText("{B}=");

        jLabel3.setText("{C}=");

        btnUnion.setText("Union");
        btnUnion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUnionActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE))
                .addGap(74, 74, 74))
            .addGroup(layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addComponent(btnUnion)
                .addContainerGap(350, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addComponent(jLabel1)
                        .addGap(94, 94, 94)
                        .addComponent(jLabel2)
                        .addGap(130, 130, 130)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnUnion)
                .addContainerGap(126, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CargarConjuntoA(PIII.Negocio.Conjunto A){
        for(int i=0;i<=3;i++){
            PIII.Negocio.Entero OBJEntero=new Entero();
            OBJEntero.setNum(Integer.parseInt(jTable1.getValueAt(0, i).toString()));
            A.insertar_vector(OBJEntero);
        }
    }
     private void CargarConjuntoB(PIII.Negocio.Conjunto B){
        for(int i=0;i<=3;i++){
            PIII.Negocio.Entero OBJEntero=new Entero();
            OBJEntero.setNum(Integer.parseInt(jTable2.getValueAt(0, i).toString()));
            B.insertar_vector(OBJEntero);
        }
    }
     private void MostrarConjunto(PIII.Negocio.Conjunto B){
         this.DimencionarVectorResultado(B.getN());
          for(int i=0;i<=B.getN()-1;i++){
              jTable3.setValueAt(B.leer_vector(i).getNum(), 0, i);
          }
       
     }
    private void btnUnionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUnionActionPerformed
        // TODO add your handling code here:
        PIII.Negocio.Conjunto A=new Conjunto();
        PIII.Negocio.Conjunto B=new Conjunto();
        PIII.Negocio.Conjunto C=new Conjunto();
        this.CargarConjuntoA(A);
        this.CargarConjuntoB(B);
        C=A.union(A, B);
        this.MostrarConjunto(C);
        
    }//GEN-LAST:event_btnUnionActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrmConjunto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnUnion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    // End of variables declaration//GEN-END:variables
}
